package com.example.demo.service;

import com.example.demo.dao.DepartmentDao;
import com.example.demo.dao.StudentDao;
import com.example.demo.domain.Department;
import com.example.demo.domain.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("studentService")
public class StudentService {
    @Autowired
    StudentDao studentDao;
    //增加
    public List<Student> addStudent(Student student){
        return studentDao.addStudent(student);
    }
    public List<Student> addStudents(List<Student> students){
        return studentDao.addStudents(students);
    }
    //查询
    public List<Student> getAll(){
        return studentDao.getAll();
    }
    public Student getOneByNo(String no){
        return studentDao.getOneByNo(no);
    }
    //更新
    public String updateStudent(Student student){
        if(studentDao.updateStudent(student)){
            return "更新成功";
        }else {
            return "更新失败 " + student.getNo() + " 不存在";
        }
    }
    //删除
    public String deleteStudent(String no){
        if(studentDao.deleteStudent(no)){
            return "删除成功";
        }else {
            return "删除失败 " + no + " 不存在";
        }
    }
}